package edu.ccut.saturn.workflow.query;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnData;
import edu.ccut.saturn.operation.Operation;

public class CheckTaskTime extends DefaultComponent {
	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		ArrayList<SaturnData> tasklist = (ArrayList<SaturnData>) parameterContext
				.getParameterValue(0);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$
		Long systime = format.parse(Operation.baseService().GetSystemTime())
				.getTime();
		Long final_timeL  = 0L;
		ArrayList <String> workitem_id_list  = new ArrayList<String>();
		Long interval = null;
		for (SaturnData task : tasklist) {
			String final_time = (String) task.get("workitem_final_time");
			if(final_time!=null&&!"".equals(final_time)){ 
				 final_timeL = format.parse(final_time).getTime();
				 interval = final_timeL - systime;
				 if(interval<0){
					 //越期
					 workitem_id_list.add(task.get("workitem_id")+"");
				 }
			}
		}
		parameterContext.setParameter(1, workitem_id_list);
	}
}